package com.java110.mall.acct.cmd.accountBond;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.mall.acct.bmo.accountBond.IUpdateAccountBondBMO;
import com.java110.po.account.AccountBondPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "accountBond.updateAccountBond")
public class UpdateAccountBondCmd extends Cmd {

    @Autowired
    private IUpdateAccountBondBMO updateAccountBondBMOImpl;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "bondName", "请求报文中未包含bondName");
        Assert.hasKeyAndValue(reqJson, "bondType", "请求报文中未包含bondType");
        Assert.hasKeyAndValue(reqJson, "amount", "请求报文中未包含amount");
        Assert.hasKeyAndValue(reqJson, "objId", "请求报文中未包含objId");
        Assert.hasKeyAndValue(reqJson, "bondMonth", "请求报文中未包含bondMonth");
        Assert.hasKeyAndValue(reqJson, "bondId", "bondId不能为空");
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        AccountBondPo accountBondPo = BeanConvertUtil.covertBean(reqJson, AccountBondPo.class);
        ResponseEntity<String> response = updateAccountBondBMOImpl.update(accountBondPo);
        context.setResponseEntity(response);
    }
}
